﻿using System;
using Microsoft.EntityFrameworkCore;
using PasteLoggerBoard.reportmodels;
using PasteLoggerBoard.serilogmodels;
using PasteLoggerBoard.usermodels;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace PasteLoggerBoard
{
    /// <summary>
    /// 
    /// </summary>
    public static class PasteLoggerBoardDbContextModelCreatingExtensions
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="optionsAction"></param>
        public static void ConfigurePasteLoggerBoard(
            this ModelBuilder builder,
            Action<PasteLoggerBoardModelBuilderConfigurationOptions> optionsAction = null)
        {


            Check.NotNull(builder, nameof(builder));

            var options = new PasteLoggerBoardModelBuilderConfigurationOptions(
                PasteLoggerBoardDbProperties.DbTablePrefix,
                PasteLoggerBoardDbProperties.DbSchema
            );

            optionsAction?.Invoke(options);

            /* Configure all entities here. Example:

            builder.Entity<Question>(b =>
            {
                //Configure table & schema name
                b.ToTable(options.TablePrefix + "Questions", options.Schema);
            
                b.ConfigureByConvention();
            
                //Properties
                b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength);
                
                //Relations
                b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId);

                //Indexes
                b.HasIndex(q => q.CreationTime);
            });
            */
            // *UserInfo*
            builder.Entity<UserInfo>(b =>
            {
                b.ToTable(options.TablePrefix + "UserInfo", options.Schema);
                b.ConfigureByConvention();
            });

            // *RoleInfo*
            builder.Entity<RoleInfo>(b =>
            {
                b.ToTable(options.TablePrefix + "RoleInfo", options.Schema);
                b.ConfigureByConvention();
            });

            // *GradeInfo*
            builder.Entity<GradeInfo>(b =>
            {
                b.ToTable(options.TablePrefix + "GradeInfo", options.Schema);
                b.ConfigureByConvention();
            });

            // *GradeRole*
            builder.Entity<GradeRole>(b =>
            {
                b.ToTable(options.TablePrefix + "GradeRole", options.Schema);
                b.ConfigureByConvention();
            });

            //// *PartInfo*
            //builder.Entity<PartInfo>(b =>
            //{
            //    b.ToTable(options.TablePrefix + "PartInfo", options.Schema);
            //    b.ConfigureByConvention();
            //});

            //// *BindUserPart*
            //builder.Entity<BindUserPart>(b =>
            //{
            //    b.ToTable(options.TablePrefix + "BindUserPart", options.Schema);
            //    b.ConfigureByConvention();
            //});



            //**DayReport**
            builder.Entity<DayReport>(b =>
            {
                b.ToTable(options.TablePrefix + "DayReport", options.Schema);
                b.ConfigureByConvention();
            });

            //**LogError**
            builder.Entity<LogError>(b =>
            {
                b.ToTable(options.TablePrefix + "LogError", options.Schema);
                b.ConfigureByConvention();
            });

            //**LogException**
            builder.Entity<LogException>(b =>
            {
                b.ToTable(options.TablePrefix + "LogException", options.Schema);
                b.ConfigureByConvention();
            });

            //**LogInfo**
            builder.Entity<LogInfo>(b =>
            {
                b.ToTable(options.TablePrefix + "LogInfo", options.Schema);
                b.ConfigureByConvention();
            });

            //**LogWarning**
            builder.Entity<LogWarning>(b =>
            {
                b.ToTable(options.TablePrefix + "LogWarning", options.Schema);
                b.ConfigureByConvention();
            });

            //**WebHooker**
            builder.Entity<WebHooker>(b =>
            {
                b.ToTable(options.TablePrefix + "WebHooker", options.Schema);
                b.ConfigureByConvention();
            });

            //**WebHookLink**
            builder.Entity<WebHookLink>(b =>
            {
                b.ToTable(options.TablePrefix + "WebHookLink", options.Schema);
                b.ConfigureByConvention();
            });

            //**WebHookLog**
            builder.Entity<WebHookLog>(b =>
            {
                b.ToTable(options.TablePrefix + "WebHookLog", options.Schema);
                b.ConfigureByConvention();
            });

            //**StatusHourReport**
            builder.Entity<StatusHourReport>(b =>
            {
                b.ToTable(options.TablePrefix + "StatusHourReport", options.Schema);
                b.ConfigureByConvention();
            });

            //**StatusDayReport**
            builder.Entity<StatusDayReport>(b =>
            {
                b.ToTable(options.TablePrefix + "StatusDayReport", options.Schema);
                b.ConfigureByConvention();
            });

            //**PathHourReport**
            builder.Entity<PathHourReport>(b =>
            {
                b.ToTable(options.TablePrefix + "PathHourReport", options.Schema);
                b.ConfigureByConvention();
            });

            //**PathDayReport**
            builder.Entity<PathDayReport>(b =>
            {
                b.ToTable(options.TablePrefix + "PathDayReport", options.Schema);
                b.ConfigureByConvention();
            });

            //**LevelHourReport**
            builder.Entity<LevelHourReport>(b =>
            {
                b.ToTable(options.TablePrefix + "LevelHourReport", options.Schema);
                b.ConfigureByConvention();
            });

            //**LevelDayReport**
            builder.Entity<LevelDayReport>(b =>
            {
                b.ToTable(options.TablePrefix + "LevelDayReport", options.Schema);
                b.ConfigureByConvention();
            });

            //**ClientIpHourReport**
            builder.Entity<ClientIpHourReport>(b =>
            {
                b.ToTable(options.TablePrefix + "ClientIpHourReport", options.Schema);
                b.ConfigureByConvention();
            });

            ////**ClientIpDayReport**
            //builder.Entity<ClientIpDayReport>(b =>
            //{
            //    b.ToTable(options.TablePrefix + "ClientIpDayReport", options.Schema);
            //    b.ConfigureByConvention();
            //});

//**AppInfo**
builder.Entity<AppInfo>(b =>{
b.ToTable(options.TablePrefix + "AppInfo", options.Schema);
b.ConfigureByConvention();
});

        }
    }
}